package com.euc.springbootframework.entity;


import org.springframework.data.domain.Auditable;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.data.mongodb.core.mapping.Field;

import javax.persistence.EntityListeners;
import java.time.LocalDateTime;
import java.util.Optional;

//@MappedSuperclass
@EntityListeners(value = { AuditingEntityListener.class })
public abstract class AuditBaseEntity extends AbstractMongoPersistable implements Auditable<User,String,LocalDateTime>{

    @Field
    private LocalDateTime createdDate;
    @Field
    private LocalDateTime lastModifiedDate;
    @Field
    private User createdBy;
    @Field
    private User lastModifiedBy;

    public Optional<LocalDateTime> getCreatedDate() {
        return Optional.ofNullable(createdDate);
    }

    public void setCreatedDate(LocalDateTime createDate) {
        this.createdDate = createDate;
    }

    @Override
    public Optional<LocalDateTime> getLastModifiedDate() {
        return Optional.ofNullable(lastModifiedDate);
    }

    @Override
    public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }

    @Override
    public Optional<User> getCreatedBy() {
        return Optional.ofNullable(createdBy);
    }

    @Override
    public void setCreatedBy(User createBy) {
        this.createdBy = createBy;
    }

    @Override
    public Optional<User> getLastModifiedBy() {
        return Optional.ofNullable(lastModifiedBy);
    }

    @Override
    public void setLastModifiedBy(User lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }
}
